package com.panfeng.xcloud.gateway.config;

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.annotations.ApiIgnore;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * @author xiaobo
 * @date 2018-02-07
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

	@Bean
	public Docket newsApi() {
		Predicate<String> regex = regex("/pm/.*");
		return new Docket(DocumentationType.SWAGGER_2).groupName("gateway")
				.apiInfo(apiInfo())
				.ignoredParameterTypes(ApiIgnore.class)
				.select()
				.paths(regex).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("QuantBot-网关APIs")
				.description("QuantBot-网关APIs接口文档说明")
				.termsOfServiceUrl("http://localhost:8020")
				.contact(
						new Contact("xiaobo",
								"http://192.168.18.15:81/index.php/",
								"xiaoboliyaqing@163.com")).version("1.0")
				.build();
	}

	@SuppressWarnings("deprecation")
	@Bean
	UiConfiguration uiConfig() {
		return new UiConfiguration(null, "list", "alpha", "schema",
				UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS, false, true);
	}

}
